Skip to content

Move JSON stores to source generation (trim-prep)#29

Merged
StuartMeeks merged 1 commit into
mainfrom
feat/json-source-gen
May 30, 2026
Merged

Move JSON stores to source generation (trim-prep)#29
StuartMeeks merged 1 commit into
mainfrom
feat/json-source-gen

Conversation

@StuartMeeks

Copy link
Copy Markdown
Owner

Task #9 ("Re-enable PublishTrimmed"), handled per the agreed "land the safe part, verdict on the flip" plan.

What landed (the safe, valuable part)

  • StoreJsonContext — a source-generated JsonSerializerContext for SnipStoreDocument and AppConfig. JsonSnipStore / JsonSettingsStore now serialise via the generated metadata instead of the reflection-based JsonSerializer.Serialize/Deserialize<T>, removing the IL2026 trim warnings and making serialization AOT-friendlier.
  • Wire format preserved, provably. Enum names are pinned with [JsonStringEnumMemberName] to the previous camelCase output ("choice", "dark", "hideToTray", "control"…). StoreJsonCompatibilityTests assert the source-gen output is byte-identical to the old serializer for both document and config, and that legacy JSON round-trips through the new context — so existing on-disk stores keep loading. (Fully verified on Linux.)

Verdict on the flip (PublishTrimmed stays OFF)

Source-gen cleared IL2026, but a trimmed Release publish on the Windows agent still fails IL2104 on three assemblies that aren't annotated trim-safe:

  • Microsoft.Windows.SDK.NET
  • WinRT.Runtime
  • Jdenticon

Silencing IL2104 wouldn't make trimming safe — the WinRT interop layer uses reflection, so full trimming risks runtime breakage a build can't catch. A WinUI head can't be fully trimmed without partial-trim (which only trims our own tiny assemblies → negligible savings). So PublishTrimmed stays off, with the reasoning recorded in the csproj. Revisit only if the WinAppSDK/WinRT assemblies ship trim annotations.

Net: the IL2026 half of the original blocker is resolved and the stores are source-gen'd; the size win isn't achievable yet for reasons outside our code.

Tests

  • New StoreJsonCompatibilityTests (byte-identical document + config; legacy round-trip). Full suite: 140 passing.
  • App compiles clean on the Windows build agent; the trimmed-publish IL2104 result is the documented verdict above.

🤖 Generated with Claude Code

Add StoreJsonContext (source-gen JsonSerializerContext) for SnipStoreDocument
and AppConfig, and switch JsonSnipStore/JsonSettingsStore onto the generated
metadata. This removes the IL2026 reflection-serializer trim warnings and is
AOT-friendlier.

The wire format is preserved exactly: enum names are pinned with
[JsonStringEnumMemberName] to the previous camelCase output, and
StoreJsonCompatibilityTests assert the source-gen output is byte-identical to
the old reflection serializer (and that legacy JSON round-trips), so existing
store/settings files keep loading.

PublishTrimmed stays off: source-gen cleared IL2026, but a trimmed WinUI
publish still fails IL2104 on Microsoft.Windows.SDK.NET, WinRT.Runtime and
Jdenticon (not trim-safe). Verdict in the csproj comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@StuartMeeks StuartMeeks merged commit 56332fb into main May 30, 2026
4 checks passed
@StuartMeeks StuartMeeks deleted the feat/json-source-gen branch May 30, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant